using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace dotnet_ef_admin.Src.Models;

// [Table("menu")]
// public class Menu {
//     [Key] public int Id { get; set; }

//     [Column("parent_id")] public int ParentId { get; set; } = 0;

//     [Column("tree_path")] public string? TreePath { get; set; }

//     [Required] public required string Name { get; set; }

//     [Required] public int Type { get; set; }

//     public string? Path { get; set; }

//     public string? Component { get; set; }

//     public string? Perm { get; set; }

//     public int? Visible { get; set; } = 1;

//     public int? Sort { get; set; } = 0;

//     public string? Icon { get; set; }

//     public string? Redirect { get; set; }

//     [Column("create_time")] public DateTime? CreateTime { get; set; } = DateTime.Now;

//     [Column("update_time")] public DateTime? UpdateTime { get; set; }

//     [Column("always_show")] public int? AlwaysShow { get; set; }

//     [Column("keep_alive")] public int? KeepAlive { get; set; }

//     public ICollection<RolesOnMenus> Roles { get; set; } = [];
// }


[Table("menu")]
public class Menu {
    /// <summary>
    /// 菜单ID
    /// </summary>
    [Key]
    public int Id { get; set; }

    /// <summary>
    /// 父菜单ID
    /// </summary>
    [Column("parent_id")]
    public int ParentId { get; set; } = 0;

    /// <summary>
    /// 菜单名称
    /// </summary>
    [Required]
    [MaxLength(100)] // 设置最大长度
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 菜单类型(1-菜单；2-目录；3-外链；4-按钮权限)
    /// </summary>
    public MenuTypeEnum Type { get; set; }

    /// <summary>
    /// 路由名称（Vue Router 中定义的路由名称）
    /// </summary>
    [MaxLength(100)]
    [Column("route_name")]
    public string RouteName { get; set; } = string.Empty;

    /// <summary>
    /// 路由路径（Vue Router 中定义的 URL 路径）
    /// </summary>
    [MaxLength(200)]
    [Column("route_path")]
    public string RoutePath { get; set; } = string.Empty;

    /// <summary>
    /// 组件路径(vue页面完整路径，省略.vue后缀)
    /// </summary>
    [MaxLength(200)]
    public string Component { get; set; } = string.Empty;

    /// <summary>
    /// 权限标识
    /// </summary>
    [MaxLength(50)]
    public string Perm { get; set; } = string.Empty;

    /// <summary>
    /// 显示状态(1:显示;0:隐藏)
    /// </summary>
    public int Visible { get; set; } = 1;

    /// <summary>
    /// 排序
    /// </summary>
    public int Sort { get; set; } = 0;

    /// <summary>
    /// 菜单图标
    /// </summary>
    [MaxLength(100)]
    public string Icon { get; set; } = string.Empty;

    /// <summary>
    /// 跳转路径
    /// </summary>
    [MaxLength(200)]
    public string Redirect { get; set; } = string.Empty;

    /// <summary>
    /// 父节点路径，以英文逗号(,)分割
    /// </summary>
    [MaxLength(500)]
    [Column("tree_path")]
    public string TreePath { get; set; } = string.Empty;

    /// <summary>
    /// 【菜单】是否开启页面缓存(1:开启;0:关闭)
    /// </summary>
    [Column("keep_alive")]
    public int KeepAlive { get; set; }

    /// <summary>
    /// 【目录】只有一个子路由是否始终显示(1:是 0:否)
    /// </summary>
    [Column("always_show")]
    public int AlwaysShow { get; set; }

    /// <summary>
    /// 路由参数
    /// </summary>
    public string Params { get; set; } = string.Empty;

    /// <summary>
    /// 创建时间
    /// </summary>
    [Column("create_time")] public DateTime? CreateTime { get; set; } = DateTime.Now;

    /// <summary>
    /// 更新时间
    /// </summary>
    [Column("update_time")] public DateTime? UpdateTime { get; set; }


    public ICollection<RolesOnMenus> Roles { get; set; } = [];
}

// 注意：需要定义 MenuTypeEnum 枚举
public enum MenuTypeEnum {
    Menu = 1,
    Directory,
    ExternalLink,
    ButtonPermission
}